﻿using System;
using System.Reflection;

namespace YArchitech.MEP
{
	public class HYTubeShapeDescription : Attribute
	{
		public HYTubeShapeDescription(string text)
		{
			this.Text = text;
		}

		public static string ToString(Enum en)
		{
			Type type = en.GetType();
			MemberInfo[] member = type.GetMember(en.ToString());
			if (member != null && member.Length > 0)
			{
				object[] customAttributes = member[0].GetCustomAttributes(typeof(HYTubeShapeDescription), false);
				if (customAttributes != null && customAttributes.Length > 0)
				{
					return ((HYTubeShapeDescription)customAttributes[0]).Text;
				}
			}
			return en.ToString();
		}

		public static HYTubeShape ToShape(string shapeString)
		{
			HYTubeShape result = HYTubeShape.Round;
			if (Enum.TryParse<HYTubeShape>(shapeString, out result))
			{
				return result;
			}
			if ("矩形" == shapeString)
			{
				return HYTubeShape.Rectangular;
			}
			if ("扁圆形" == shapeString)
			{
				return HYTubeShape.Oval;
			}
			return HYTubeShape.Round;
		}

		private string Text;
	}
}
